package com.sx.zongzhi.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.activity.BuildingLayoutActivity;
import com.sx.zongzhi.bean.BuildingListBean;

import java.util.List;

/**
 * Created by XZY on 2017/1/13.
 * 楼宇列表adapter
 */

public class BuildingListAdapter extends BaseQuickAdapter<BuildingListBean.RowsBean,BaseViewHolder> {

    private Context context;

    public BuildingListAdapter(Context context, @LayoutRes int layoutResId, @Nullable
            List<BuildingListBean.RowsBean> data) {
        super(layoutResId, data);
        this.context=context;
    }


    @Override
    protected void convert(BaseViewHolder helper, final BuildingListBean.RowsBean item) {
        helper.setText(R.id.tv_BuildingName,item.getBuildingname());
        helper.setText(R.id.tv_Time,item.getCreateDate());
        helper.setText(R.id.tv_Address,item.getBuildingaddress());
        TextView tvBtn=helper.getView(R.id.tv_Btn);
        tvBtn.setText(item.isLayout()?"生成布局":"绑定楼宇");
        tvBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, BuildingLayoutActivity.class)
                .putExtra("BuildingId",item.getId())
                .putExtra("Layout",item.isLayout()));
            }
        });
    }
}
